{%include file="../public/top.html"%}

<div id="content-header">
    <h1>素材管理</h1>
    <div class="btn-group">
        <a class="btn btn-primary btn-large" href="/matter_manage/add_matter">添加素材</a>
    </div>
</div>
<div id="breadcrumb">
    <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> 首页</a>
    <a href="#" class="current">素材管理</a>
</div>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="widget-box">
                <div class="widget-title">
								<span class="icon">
									<i class="icon-th"></i>
								</span>
                    <h5>素材列表</h5>
                </div>
                <div class="widget-content">
                    <ul class="thumbnails">
                        {%foreach from=$datas item=data%}
                            <li class="span2">
                                <a href="javascript:void(0)" class="thumbnail">
                                    <img src="{%$data.img_path%}" style="width: 150px;height:200px;" />
                                </a>
                                <div class="actions">
                                    <a title="编辑" href="/matter_manage/update_matter?id={%$data.id%}"><i class="icon-pencil icon-white inselected"></i></a>
                                    <a data-url="/matter_manage/can_search" class="can_search" data-status="{%$data.status%}" data-id="{%$data.id%}" href="javascript:void(0)"><i class="icon-ok icon-white" title="是否可以搜索"></i></a>
                                    <a data-url="/matter_manage/del_matter" class="del_matter" data-id="{%$data.id%}" href="javascript:void(0)"><i class="icon-remove icon-white" title="删除"></i></a>
                                </div>
                                <p style="text-align: center;color: red;font-size: 20px;padding-top: 10px;">{%$data.field_name%} {%if $data.status eq 2%}(可搜索){%/if%}</p>
                            </li>
                        {%/foreach%}
                    </ul>
                </div>
            </div>
        </div>
    </div>
    {%include file="../public/bottom.html"%}
    <script>
        $('.del_matter').on('click',function(){
            var id = $(this).data('id');
            var url = $(this).data('url');
            if(confirm('确定要删除么?')){
                $.ajax({
                    url : url,
                    data:{'id':id},
                    type: 'post',
                    dataType:'json',
                    success:function(result){
                        if(result.code !== 200){
                            alert(result.message);
                            return;
                        }else{
                            alert(result.message);
                            window.location.reload();
                        }
                    }
                });
            }else{
                return;
            }
        });

        $('.can_search').on('click',function(){
            var id = $(this).data('id');
            var url = $(this).data('url');
            var status = $(this).data('status');
            status =  status == 1 ? 2 : 1;
            if(confirm('是否设置搜索选项?')){
                $.ajax({
                    url : url,
                    data:{'id':id,
                          'status':status},
                    type: 'post',
                    dataType:'json',
                    success:function(result){
                        if(result.code !== 200){
                            alert(result.message);
                            return;
                        }else{
                            alert(result.message);
                            window.location.reload();
                        }
                    }
                });
            }else{
                return;
            }
        });
    </script>